package com.qifeng.modules.resumeInfo.controller;

import com.qifeng.common.base.RestResponse;
import com.qifeng.modules.resumeInfo.domain.ResumeInfo;
import com.qifeng.modules.resumeInfo.service.ResumeInfoService;
import io.swagger.annotations.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "resumeInfo")
@RequestMapping("api")
public class ResumeInfoController {

	private static Logger logger = Logger.getLogger(ResumeInfoController.class);

	@Autowired
	private ResumeInfoService resumeInfoService;

	/**
	* 获取列表
	*
	* @param response
	* @return
	*/
	@ApiOperation(value = "分页查询所有", notes = "")
	@ApiResponses({
		@ApiResponse(code = 200, message = "查询成功"),
		@ApiResponse(code = 404, message = "查询失败", response = RestResponse.class)
	})
	@GetMapping("resumeInfos")
    public RestResponse<Page<ResumeInfo>> findPage(Pageable pageable, RestResponse response) {
		return response.success(resumeInfoService.findPage(pageable));
	}

	/**
	* 新增
	*
	* @param resumeInfo 新增实体，前端数据需要 JSON.stringify(data)
	* @param response
	* @return
	*/
    @ApiOperation(value = "新增", notes = "")
    @ApiResponses({
        @ApiResponse(code = 200, message = "添加成功"),
        @ApiResponse(code = 400, message = "参数验证失败", response = RestResponse.class)
    })
    @PostMapping("resumeInfo")
    public RestResponse create(@ApiParam(value = "实体", required = true)
                                 @RequestBody ResumeInfo resumeInfo,
                               RestResponse response) {
        return response.success(resumeInfoService.create(resumeInfo));
    }

	/**
	* 更新
	*
	* @param resumeInfo 更新实体，前端数据需要 JSON.stringify(data)
	* @param response
	* @return
	*/
    @ApiOperation(value = "修改", notes = "")
    @ApiResponses({
        @ApiResponse(code = 201, message = "修改成功"),
        @ApiResponse(code = 400, message = "参数验证失败", response = RestResponse.class)
    })
    @PatchMapping("resumeInfo")
    public RestResponse update(@ApiParam(value = "实体", required = true)
                                 @RequestBody ResumeInfo resumeInfo,
                               RestResponse response) {
        return response.success(resumeInfoService.update(resumeInfoService.findOne(resumeInfo)));
    }

	/**
	* 删除
	*
	* @param id 主键
	* @param response
	* @return
	*/
    @ApiOperation(value = "删除", notes = "")
    @ApiResponses({
        @ApiResponse(code = 201, message = "修改成功"),
        @ApiResponse(code = 400, message = "参数验证失败", response = RestResponse.class)
    })
    @DeleteMapping("resumeInfo")
    public RestResponse delete(@ApiParam(value = "主键", required = true)
                                 @RequestParam Long id,
                               RestResponse response) {
        resumeInfoService.delete(resumeInfoService.findOne(id));
        return response.success();
    }
    /**
    * 根据ID查找
    *
    * @param id       主键
    * @param response
    * @return
    */
    @ApiOperation(value = "通过主键查找", notes = "")
    @ApiResponses({
        @ApiResponse(code = 200, message = "查询成功"),
        @ApiResponse(code = 404, message = "查询失败", response = RestResponse.class)
    })
    @GetMapping("resumeInfo")
    public RestResponse<ResumeInfo> findOne(@ApiParam(value = "主键", required = true)
                                  @RequestParam Long id,
                                            RestResponse response) {
        return response.success(resumeInfoService.findOne(id));
    }
}